function developing() {
    toastr['success']('开发中！！！！', '提示');
}

function filePathFormatter(value, row, index) {
    var url = "/public/download?filePath=" + value;
    var tempWindow = window.open('about:blank');
    window.open(url, tempWindow);
}

function removeDecimal(num) {
    var str = num + "";
    if (str.indexOf(".") > 0) {
        return str.substring(0, str.indexOf("."));
    } else {
        return str;
    }
}


function number_format(number, decimals, dec_point, thousands_sep) {

    number = (number + '').replace(/[^0-9+-Ee.]/g, '');
    var n = !isFinite(+number) ? 0 : +number,
        prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
        sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
        dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
        s = '',
        toFixedFix = function (n, prec) {
            var k = Math.pow(10, prec);
            return '' + Math.ceil(n * k) / k;
        };

    s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
    var re = /(-?\d+)(\d{3})/;
    while (re.test(s[0])) {
        s[0] = s[0].replace(re, "$1" + sep + "$2");
    }

    if ((s[1] || '').length < prec) {
        s[1] = s[1] || '';
        s[1] += new Array(prec - s[1].length + 1).join('0');
    }
    return s.join(dec);
}

function indexFormatter(value, row, index) {
    return index + 1;
}




function dateFormatter(value, row, index) {
    if (value == "" || value == undefined)
        return value;
    return value.substr(0, 4) + "-" + value.substr(4, 2) + "-" + value.substr(6, 2);
}

function timeFormatter(value, row, index) {
    if (value == "" || value == undefined)
        return value;
    return value.substr(0, 2) + ":" + value.substr(2, 2) + ":" + value.substr(4, 2);
}

function tipFormatter(value, row, index) {
    if (value == "" || value == undefined)
        return "";
    if (value.length < 10) {
        return value;
    }
    return "<a href='javascript:void(0)' onclick='showTip(\"" + value + "\")'>" + value.substr(0, 10) + "...</a>";
}

function showTip(value) {
    $("#bodyDiv").html(value);
    $("#tipModal").modal("show");
}

function postReq(url, data, callBack) {
    $.ajax({
        type: 'POST',
        url: url,
        dataType: "json",
        data: JSON.stringify(data),
        contentType: "application/json; charset=utf-8",
        success: callBack
    });
}

function getReq(url, callBack) {
    $.ajax({
        type: 'GET',
        url: url,
        contentType: "application/json; charset=utf-8",
        success: callBack
    });
}

function fileReq(url, fileElementId, data, callBack) {
    $.ajaxFileUpload({
        url: url,
        secureuri: false,
        fileElementId: fileElementId,//file标签的id
        dataType: 'json',//返回数据的类型
        data: data,//一同上传的数据
        success: callBack
    });
}

Date.prototype.pattern = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1, //月份
        "d+": this.getDate(), //日
        "h+": this.getHours() % 12 == 0 ? 12 : this.getHours() % 12, //小时
        "H+": this.getHours(), //小时
        "m+": this.getMinutes(), //分
        "s+": this.getSeconds(), //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds() //毫秒
    };
    var week = {
        "0": "/u65e5",
        "1": "/u4e00",
        "2": "/u4e8c",
        "3": "/u4e09",
        "4": "/u56db",
        "5": "/u4e94",
        "6": "/u516d"
    };
    if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    if (/(E+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? "/u661f/u671f" : "/u5468") : "") + week[this.getDay() + ""]);
    }
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        }
    }
    return fmt;
};

function confirm(confirm, dismiss) {
    swal({
        title: "",
        text: "确定操作？",
        type: "warning",
        showCancelButton: "true",
        showConfirmButton: "true",
        cancelButtonText: "取消",
        confirmButtonText: "确认"
    }).then(function (isConfirm) {
        if (isConfirm.value == true) {
            confirm;
        } else if (isConfirm.dismiss == 'cancel') {
            dismiss;
        }
    });
}

function setFormValue(url, field, selectId) {
    getReq(url, function (result) {
        $("#" + field).append("<option>请选择</option>");
        for (var i = 0; i < result.length; i++) {
            if(undefined != selectId && selectId != "" &&  result[i].value == selectId )  {
                $("#" + field).append("<option value='" + result[i].value + "' selected='selected'>" + result[i].name + "</option>");
            } else {
                $("#" + field).append("<option value='" + result[i].value + "'>" + result[i].name + "</option>");
            }
        }
        // .select2()在select基础上增加了些属性操作
        $("#" + field).select2();
    });
}
function setFormJsonValue(json,field,selectId) {
    var result = JSON.parse(json) ;
    $("#" + field).append("<option>请选择</option>");
    for (var i = 0; i < result.length; i++) {
        if(undefined != selectId && selectId != "" &&  result[i].value == selectId )  {
            $("#" + field).append("<option value='" + result[i].value + "' selected='selected'>" + result[i].name + "</option>");
        } else {
            $("#" + field).append("<option value='" + result[i].value + "'>" + result[i].name + "</option>");
        }
    }
    $("#" + field).select2();
}